package com.xiaoyu.merchant;

import android.app.Application;
import android.content.Context;


import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.techfansy.moreImageSelected.ImagePicker;
import com.techfansy.moreImageSelected.UILImageLoader;
import com.techfansy.moreImageSelected.view.CropImageView;
import com.umeng.commonsdk.UMConfigure;
import com.umeng.socialize.PlatformConfig;
import com.xiaoyu.commonlib.CommonPlug;
import com.xiaoyu.commonlib.plug.PlugManager;
import com.xiaoyu.commonlib.utils.UIUtils;

/**
 * Created by jk on 2018/9/29.
 */
public class MerchantApplication extends Application {

    public static Context mCotext;

    @Override
    public void onCreate() {
        super.onCreate();
        mCotext = this;
        UIUtils.init(this);
        initImagePicker();
        initUniversalImageLoader();
        initPlug();
        initPlatform();
    }

    private void initPlatform() {
        /**
         * 初始化common库
         * 参数1:上下文，不能为空
         * 参数2:设备类型，UMConfigure.DEVICE_TYPE_PHONE为手机、UMConfigure.DEVICE_TYPE_BOX为盒子，默认为手机
         * 参数3:Push推送业务的secret
         */
        UMConfigure.init(this, UMConfigure.DEVICE_TYPE_PHONE, MerchantConstants.APP_KEY_UMENG);
    }

    {
        PlatformConfig.setWeixin(MerchantConstants.APP_ID_WECHAT, MerchantConstants.App_Secret_WECHAT);
    }

    private void initPlug() {
        PlugManager.getInstance().addPlugRules(PlugManager.MASTER_ID, new MerchantPlugRuleImpl());
        CommonPlug commonPlug = new CommonPlug();
        commonPlug.initPlug(this);
    }

    private void initUniversalImageLoader() {
        //初始化ImageLoader
        ImageLoader.getInstance().init(
                ImageLoaderConfiguration.createDefault(getApplicationContext()));
    }

    /**
     * 初始化仿微信控件ImagePicker
     */
    private void initImagePicker() {
        ImagePicker imagePicker = ImagePicker.getInstance();
        imagePicker.setImageLoader(new UILImageLoader());   //设置图片加载器
//        imagePicker.setShowCamera(true);  //显示拍照按钮
        imagePicker.setShowCamera(false);  //不显示拍照按钮
//        imagePicker.setCrop(true);        //允许裁剪（单选才有效）
        imagePicker.setCrop(false);        //不允许裁剪（单选才有效）
        imagePicker.setSaveRectangle(true); //是否按矩形区域保存
        imagePicker.setSelectLimit(8);    //选中数量限制
        imagePicker.setStyle(CropImageView.Style.RECTANGLE);  //裁剪框的形状
        imagePicker.setFocusWidth(800);   //裁剪框的宽度。单位像素（圆形自动取宽高最小值）
        imagePicker.setFocusHeight(800);  //裁剪框的高度。单位像素（圆形自动取宽高最小值）
        imagePicker.setOutPutX(1000);//保存文件的宽度。单位像素
        imagePicker.setOutPutY(1000);//保存文件的高度。单位像素
    }

    public static Context getAppContext() {
        return mCotext;
    }
}
